﻿@model IEnumerable<EdexApiClient.WH_LOCATIONS>

@{
    ViewBag.Title = "Справочник складов";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<header class="jumbotron subhead" id="overview">
    <h1></h1>
    <p class="lead">Справочник складов</p>
</header>

<form>
    <div class="input-append">
        <input type="text" class="input-xxlarge" name="search" value="@Request["search"]" />
        <button class="btn" type="submit"><i class="icon-filter"></i> Фильтр</button>
    </div>
</form>

<table data-name="LOCATIONS" class="table table-striped">
    <thead>
        <tr>
            <th>Код</th>
            <th>Наименование</th>
            <th>Страна</th>
            <th>Индекс</th>
            <th>Город</th>
            <th>Улица</th>
            <th>№ дома</th>
            <th>Примечание</th>
        </tr>
    </thead>
    <tbody>
        @foreach (var record in Model) {
        <tr data-index="@record.GUID_RECORD">
            <td>@record.EXT_KEY</td>
            <td>@record.LOCATION_NAME</td>
            <td>@record.COUNTRY</td>
            <td>@record.POSTAL_CODE</td>
            <td>@record.CITY</td>
            <td>@record.STREET</td>
            <td>@record.BUILDING_NUMBER</td>
            <td>@record.NOTE</td>
        </tr>
        }
    </tbody>
</table>

<p>
    <a href="#" class="btn" data-action="LOCATION-CREATE"><i class="icon-plus"></i> Создать новый склад</a>
</p>

<div id="location-details"></div>


<script type="text/javascript">

    $(function () {

        $("table[data-name='LOCATIONS'] tr td[data-type!='noclick']").live("click", function () {

            var id = $(this).parent().attr("data-index");

            $("#location-details").load('/location/details/' + id, function () {
                $('.modal[data-name="LOCATIONS"]').modal("show");
            });
        });

        $(".btn[data-action='LOCATION-CREATE']").live("click", function () {

            $("#location-details").load('/location/detailsnew/', function () {
                $('.modal[data-name="LOCATIONS"]').modal("show");
            });

        });

        $(".btn[data-action='LOCATION-DELETE']").live("click", function () {

            var id = $("form[name='LOCATIONS'] *[name='GUID_RECORD']").val();

            $.ajax({
                type: 'POST',
                url: '/location/delete/' + id,
                success: function () {
                    $('.modal[data-name="LOCATIONS"]').modal("hide");
                }
            });

        });

        $(".btn[data-action='LOCATION-SAVE']").live("click", function () {

            $.ajax({
                type: 'POST',
                url: '/location/save/',
                data: $("form[name='LOCATIONS']").serialize(),
                success: function () {
                    $('.modal[data-name="LOCATIONS"]').modal("hide");
                }
            });

        });

    });

</script>